package com.three.iot.rest.controller.common;

import com.three.iot.api.SysDictService;
import com.three.iot.commons.dto.SysDictResultDto;
import com.three.iot.commons.enums.Result;
import com.three.iot.commons.enums.ResultCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author:luiz
 * @Date: 2018/2/1 14:49
 * @Descripton:基础数据
 * @Modify :
 **/
@Component
public class AbstractDictController {
    @Resource
    SysDictService sysDictService;
    private static final Logger logger= LoggerFactory.getLogger(AbstractDictController.class);

    @RequestMapping(value = "findByPdictCode", method = RequestMethod.GET)
    @ApiOperation(value = "按照上级字典编码查询下级字典", notes = "按照上级字典编码查询下级字典")
    @ApiParam(name = "pDictCode", value = "按照上级字典编码查询下级字典 pDictCode", required = true)
    public Result<List<SysDictResultDto>> findByPDict(@RequestParam(required = true) String pDictCode) {
        try {
            return sysDictService.findByPDictEnable(pDictCode);
        } catch (Exception e) {
            logger.error("[数据字典]按照上级字典编码查询下级字典异常:{}", e);
            return Result.newError(ResultCode.FAIL);
        }
    }


}
